package org.glorylight.hacks.social.model;

import java.io.Serializable;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

@Entity
@Table(name = "scrap_votes")
public class ScrapBookVotes implements Serializable {

	private static final long serialVersionUID = 5917992664555191639L;

	@Id
	@Type(type = "uuid")
	@Column(length = 32)
	private UUID uuid;

	@ManyToOne
	@JoinColumn(name = "scrapbook_id")
	private ScrapBook scrapBook;

	private Voter voter;

	public ScrapBookVotes() {
	}

	public ScrapBookVotes(UUID uuid, ScrapBook scrapBook, Voter voter) {
		this.uuid = uuid;
		this.scrapBook = scrapBook;
		this.voter = voter;
	}

	public UUID getUuid() {
		return uuid;
	}

	public void setUuid(UUID uuid) {
		this.uuid = uuid;
	}

	public ScrapBook getScrapBook() {
		return scrapBook;
	}

	public void setScrapBook(ScrapBook scrapBook) {
		this.scrapBook = scrapBook;
	}

	public Voter getVoter() {
		return voter;
	}

	public void setVoter(Voter voter) {
		this.voter = voter;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((scrapBook == null) ? 0 : scrapBook.hashCode());
		result = prime * result + ((voter == null) ? 0 : voter.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ScrapBookVotes other = (ScrapBookVotes) obj;
		if (scrapBook == null) {
			if (other.scrapBook != null)
				return false;
		} else if (!scrapBook.equals(other.scrapBook))
			return false;
		if (voter == null) {
			if (other.voter != null)
				return false;
		} else if (!voter.equals(other.voter))
			return false;
		return true;
	}

}